/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.thinkgem.jeesite.modules.house.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.thinkgem.jeesite.common.utils.Collections3;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.act.utils.ActUtils;
import com.thinkgem.jeesite.modules.house.dao.XiaoquDao;
import com.thinkgem.jeesite.modules.house.entity.Xiaoqu;
import com.thinkgem.jeesite.modules.oa.dao.LeaveDao;
import com.thinkgem.jeesite.modules.oa.entity.Leave;
import org.activiti.engine.*;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 请假Service
 * @author liuj
 * @version 2013-04-05
 */
@Service
@Transactional(readOnly = true)
public class XiaoquService extends BaseService {

	@Autowired
	private XiaoquDao xiaoquDao;

	/**
	 * 获取流程详细及工作流参数
	 * @param id
	 */
	@SuppressWarnings("unchecked")
	public Xiaoqu get(String id) {
		Xiaoqu xiaoqu = xiaoquDao.get(id);
		return xiaoqu;
	}
	
	/**
	 * 启动流程
	 * @param xiaoqu
	 */
	@Transactional(readOnly = false)
	public void save(Xiaoqu xiaoqu) {
		
		// 保存业务数据
		if (StringUtils.isBlank(xiaoqu.getId())){
			xiaoqu.preInsert();
			xiaoquDao.insert(xiaoqu);
		}else{
			xiaoqu.preUpdate();
			xiaoquDao.update(xiaoqu);
		}
		logger.debug("save entity: {}", xiaoqu);
	}

	public Page<Xiaoqu> find(Page<Xiaoqu> page, Xiaoqu xiaoqu) {

		xiaoqu.getSqlMap().put("dsf", dataScopeFilter(xiaoqu.getCurrentUser(), "o", "u"));

		xiaoqu.setPage(page);
		page.setList(xiaoquDao.findList(xiaoqu));
		
		return page;
	}
}
